package com.geek.crowdhub.dto.mapper.business;

import cn.hutool.core.util.ObjectUtil;
import com.geek.crowdhub.dto.model.business.PayOrderDto;
import com.geek.crowdhub.model.business.CampaignDetail;
import com.geek.crowdhub.model.business.PayOrder;
import com.geek.crowdhub.model.business.Perk;
import com.geek.crowdhub.model.common.User;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Component
public class PayOrderMapper {
    @Autowired
    private ModelMapper modelMapper;

    public PayOrderDto toPayOrderDto(PayOrder model) {
        if (ObjectUtil.isEmpty(model)) {
            return null;
        }
        return modelMapper.map(model,PayOrderDto.class);
    }

    public PayOrder toModel(PayOrderDto dto) {
        PayOrder payOrder = new PayOrder();
        payOrder.setId(dto.getId())
                .setOwner(new User().setId(dto.getOwnerId()))
                .setCampaignDetail(new CampaignDetail().setId(dto.getCampaignDetailId()))
                .setPerk(new Perk().setId(dto.getPerkId()));
        return payOrder;
    }
}
